package com.myBlog.controller;

import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.entity.User;
import com.myBlog.domain.vo.AdminUserInfoVO;
import com.myBlog.domain.vo.RoutersVo;
import com.myBlog.service.LoginService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
        return loginService.login(user);
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/user/getInfo")
    public ResponseResult<AdminUserInfoVO> getInfo() {
        return loginService.getInfo();
    }

    /**
     * 获取路由
     * @return
     */
    @GetMapping("/getRouters")
    public ResponseResult<RoutersVo> getRouters() {
        //封装数据返回
        return loginService.getRouters();
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping("/user/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

}
